# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time

  # See ActionController::RequestForgeryProtection for details
  # Uncomment the :secret if you're not using the cookie session store
  # protect_from_forgery # :secret => 'b2fe796ab275f4e57e52d86a92d9be14'

  # 包含了校内参数的跳转辅助方法
  def make_xiaonei_redirection options={}
    xiaonei_params = {"xn_sig_session_key"=>params[:xn_sig_session_key], "xn_sig_user" => params[:xn_sig_user]}
    xiaonei_params.merge!(options)
    redirect_to xiaonei_params
  end  

  def check_app_user
    # 其实只需要user_id就可以了，如果没有user_id，就获取一个@user对象
    if params[:xn_sig_user] == nil
      @user = xiaonei_session.invoke_method("xiaonei.users.getInfo", :uids => params[:xn_sig_user], :fields => ["uid"])     
      @user = @user.first
    else
      @user = Xiaonei::User.new
      @user.uid = params[:xn_sig_user]
    end    
  end  
end

class Rating < ActiveRecord::Base
  belongs_to :couple, 
    :class_name => "Couple",
    :foreign_key => "rated_id"
end
